{% extends "base.html" %} {% block content %}
<article class="mb-4">
  <h2 class="mb-3">{{ post.title }}</h2>
  <p class="text-muted mb-4">
    作者:
    <a href="{{ url_for('user_posts', username=post.author.username) }}"
      >{{ post.author.username }}</a
    >
    | 发布时间: {{ post.date_posted.strftime('%Y-%m-%d %H:%M') }}
  </p>

  {% if post.author == current_user %}
  <div class="mb-4">
    <a
      href="{{ url_for('update_post', post_id=post.id) }}"
      class="btn btn-sm btn-outline-primary"
      >编辑</a
    >
    <button
      type="button"
      class="btn btn-sm btn-outline-danger"
      data-bs-toggle="modal"
      data-bs-target="#deleteModal"
    >
      删除
    </button>
  </div>
  {% endif %}

  <div class="card">
    <div class="card-body">
      <p class="card-text">{{ post.content }}</p>
    </div>
  </div>
</article>

<!-- 删除确认模态框 -->
<div
  class="modal fade"
  id="deleteModal"
  tabindex="-1"
  aria-labelledby="deleteModalLabel"
  aria-hidden="true"
>
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="deleteModalLabel">确认删除</h5>
        <button
          type="button"
          class="btn-close"
          data-bs-dismiss="modal"
          aria-label="Close"
        ></button>
      </div>
      <div class="modal-body">你确定要删除这篇文章吗？此操作不可撤销。</div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
          取消
        </button>
        <form
          action="{{ url_for('delete_post', post_id=post.id) }}"
          method="POST"
        >
          <button type="submit" class="btn btn-danger">删除</button>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}
